<?php

namespace App\Exceptions\Api;

use App\Exceptions\Exception;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Throwable;

class AuthGrzqException extends Exception
{
    protected $id = 0;
    public function __construct(string $message = "", int $http_status = 200, int $admin_id = 0)
    {
        parent::__construct($message);
        $this->id = $admin_id;
    }

    public function render(Request $request,\Throwable $exception)
    {
        if ($exception instanceof ValidationException) {
            return response()->json([
                'code' => 1,
                'message' => '调用参数错误',
                'data' => $exception->errors(),
            ], 0);
        }

        if ($request->expectsJson()) {
            return $this->sendApiError($this->getMessage(), $this->getCode());
        }
        return $this->sendApiError($this->getMessage(), $this->getCode());
    }
}
